<?php
/**
 * Created by PhpStorm.
 * User: 式神 (luck48.com)
 * Email: 289650682@qq.com
 * Name: ${NAME}Administrator
 * Date: 2017-04-11
 * Time: 9:18
 */
namespace App\Http\Controllers\Admin;

use App\Http\Models\Message;
use Illuminate\Http\Request;

class MessageController extends CommonController
{
    //留言列表
    public function messageList(Request $request)
    {
        if ($request->isMethod('post')) {
            $json = [];
            $model = new Message();
            $list = $model->orderBy('id', 'Desc')->get();
            $data['list'] = $list;
            $data['title'] = trans('config.listtitle');
            $json['status'] = 200;
            $json['data'] = $data;
            return $json;
        }
        return view('admin.message.list');
    }

    //删除
    public function messageDel(Request $request){
        if($request->isMethod('post')){
            $id=Input::get('id');
            $id=explode(",", $id);
            $m=new Message();
            DB::beginTransaction();
            try{
                $m->whereIn('id',$id)->delete();
                $d=[
                    'pid'=>0
                ];
                $m->whereIn('pid',$id)->update($d);
                DB::commit();
                $data['status']=200;
                $data['msg']=trans('config.submit_success');
                $data['url']='reload';
            }catch (\Exception $e) {
                DB::rollBack();
                $data['status']=300;
                $data['msg']=trans('config.submit_error');
            }
            return $data;
        }
    }
}